#pragma once

#include "Protocol.hpp"
#include <memory>
#include <iostream>

class NetCal
{
public:
    NetCal()
    {
    }

    ~NetCal()
    {
    }

    std::shared_ptr<Response> Calculator(std::shared_ptr<Request> req)
    {
        auto resp = Factory::BuidResponseDefault();
        switch (req->_oper)
        {
        case '+':
            resp->_result = req->_x + req->_y;
            break;
        case '-':
            resp->_result = req->_x - req->_y;
            break;
        case '*':
            resp->_result = req->_x * req->_y;
            break;
        case '/':
        {
            if (req->_y == 0)
            {
                resp->_code = 1;
                resp->_desc = "div zero";
            }
            else
            {
                resp->_result = req->_x / req->_y;
            }
        }
        break;
        case '%':
            if (req->_y == 0)
            {
                resp->_code = 1;
                resp->_desc = "mode zero";
            }
            else
            {
                resp->_result = req->_x % req->_y;
            }
            break;
        default:
            resp->_code = 2;
            resp->_desc = "非法操作";
            break;
        }
        return resp;
    }
};